package org.baojie;

import org.baojie.raft.RaftCluster;
import org.baojie.raft.group.RaftGroup;
import org.baojie.raft.node.NodeAddress;
import org.baojie.raft.node.NodeName;

import java.io.File;

public class RaftStarter {

    public static void main(String[] args) {

        //       4497
        //       6168
        //       5050

        //       2848
        //       1563
        //       7986

        File file = new File("/home/baojie/baojie-raft-test/");

        NodeAddress address_0 = new NodeAddress("127.0.0.1", 4497);
        NodeName name_0 = new NodeName("4497", address_0);
        NodeAddress address_1 = new NodeAddress("127.0.0.1", 6168);
        NodeName name_1 = new NodeName("6168", address_1);
        NodeAddress address_2 = new NodeAddress("127.0.0.1", 5050);
        NodeName name_2 = new NodeName("5050", address_2);
        NodeAddress address_3 = new NodeAddress("127.0.0.1", 2848);
        NodeName name_3 = new NodeName("2848", address_3);
        NodeAddress address_4 = new NodeAddress("127.0.0.1", 1563);
        NodeName name_4 = new NodeName("1563", address_4);


        RaftGroup group_0 = new RaftGroup(name_0);

        group_0.addMember("4497", name_0);
        group_0.addMember("6168", name_1);
        group_0.addMember("5050", name_2);
        group_0.addMember("2848", name_3);
        group_0.addMember("1563", name_4);

        RaftCluster cluster_0 = new RaftCluster(file, group_0);
        cluster_0.start();

        RaftGroup group_1 = new RaftGroup(name_1);
        group_1.addMember("4497", name_0);
        group_1.addMember("6168", name_1);
        group_1.addMember("5050", name_2);
        group_1.addMember("2848", name_3);
        group_1.addMember("1563", name_4);

        RaftCluster cluster_1 = new RaftCluster(file, group_1);
        cluster_1.start();

        RaftGroup group_2 = new RaftGroup(name_2);

        group_2.addMember("4497", name_0);
        group_2.addMember("6168", name_1);
        group_2.addMember("5050", name_2);
        group_2.addMember("2848", name_3);
        group_2.addMember("1563", name_4);

        RaftCluster cluster_2 = new RaftCluster(file, group_2);
        cluster_2.start();


        RaftGroup group_3 = new RaftGroup(name_3);
        group_3.addMember("4497", name_0);
        group_3.addMember("6168", name_1);
        group_3.addMember("5050", name_2);
        group_3.addMember("2848", name_3);
        group_3.addMember("1563", name_4);

        RaftCluster cluster_3 = new RaftCluster(file, group_3);
        cluster_3.start();

        RaftGroup group_4 = new RaftGroup(name_4);

        group_4.addMember("4497", name_0);
        group_4.addMember("6168", name_1);
        group_4.addMember("5050", name_2);
        group_4.addMember("2848", name_3);
        group_4.addMember("1563", name_4);

        RaftCluster cluster_4 = new RaftCluster(file, group_4);
        cluster_4.start();

        // 在raft平衡建立后
        // 可以通过 debug AbstractNode 类中的 SendHeartTask 达到测试主节点动态切换的测试

    }

}
